//
// MapDatatoGrid.m
// MapGridbyHong
//
// Created by 컴011 on 1/18/14.
// Copyright (c) 2014 handymap. All rights reserved.
//

#import "MapDatatoGrid.h"

@implementation MapDatatoGrid

@synthesize gridWidth, gridHeight;

- (char*) getMapDatatoGrid
{
    UIImage *myImage = [UIImage imageNamed:@"final_map.jpg"];
    
    MapData *map = [[MapData alloc] init];
    [map setUIImage:myImage];
    unsigned char * maps;
    
    gridHeight = (int)[map imageHeight];
    gridWidth = (int)[map imageWidth];
    NSLog(@"gridHeight %d", gridHeight);
    gridMapData= (char*) calloc(([map imageHeight]) * ([map imageWidth]), sizeof(char));
    
    
    for(NSUInteger i=0; i<map.imageHeight; i++){
        for (NSUInteger j=0; j<map.imageWidth; j++) {
            maps = [map getRGBAImagePosition:j atY:i];
            if(maps[0] <=10 && maps[1] <=10 && maps[2] <=10){ //장애물
                gridMapData[i*[map imageWidth] + j] ='0';
            }
            else if(maps[0] <=10 && maps[1] <=10 && maps[2]>=245){ //길
                gridMapData[i*[map imageWidth] +j] = '1';
            }
            else //길도 장애물도 아닌것
                gridMapData[i*[map imageWidth] +j] = '2';
        }
    }

    return gridMapData;
    
}
@end